package top.lyc829.zzl_android.ui.base_detail;

import android.graphics.Color;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.module.LoadMoreModule;
import com.chad.library.adapter.base.viewholder.BaseViewHolder;
import com.xuexiang.xutil.data.DateUtils;

import org.jetbrains.annotations.NotNull;

import top.lyc829.zzl_android.MyApp;
import top.lyc829.zzl_android.R;
import top.lyc829.zzl_android.logic.bean.SonCommentBean;

public class SonCommentsAdapter extends BaseQuickAdapter<SonCommentBean, BaseViewHolder> implements LoadMoreModule {


    public SonCommentsAdapter() {
        super(R.layout.replay_item);
    }

    @Override
    protected void convert(@NotNull BaseViewHolder baseViewHolder, SonCommentBean sonCommentBean) {
        baseViewHolder
                .setText(R.id.replay_item_username, sonCommentBean.getUserName())
                .setText(R.id.replay_item_time, DateUtils.millis2String(Long.parseLong(sonCommentBean.getCommentTime()), DateUtils.yyyyMMdd.get()))
                .setText(R.id.replay_item_text, sonCommentBean.getCommentText())
                .setText(R.id.commented_username, sonCommentBean.getCommentedUserName())
                .setText(R.id.replay_item_like_nums, String.valueOf(sonCommentBean.getCommentLikes()));

        ImageView btnLike = baseViewHolder.getView(R.id.replay_item_like_btn);
        // 已经点赞
        if (sonCommentBean.getIsLike().equals(1)) {
            btnLike.setImageResource(R.drawable.ic_baseline_thumb_up_red_20);
            ((TextView)baseViewHolder.getView(R.id.replay_item_like_nums)).setTextColor(Color.parseColor("#E54D42"));
        } else {
            btnLike.setImageResource(R.drawable.ic_baseline_thumb_up_gray_24);
            ((TextView)baseViewHolder.getView(R.id.replay_item_like_nums)).setTextColor(Color.parseColor("#8A000000"));
        }

        Glide.with(MyApp.getContext())
                .load(sonCommentBean.getImgUrl())
                .into((ImageView) baseViewHolder.getView(R.id.replay_item_avatar));
    }
}
